package com.bjmashibing.system.huawei.jdbc;

import com.bjmashibing.system.huawei.udp_cmd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Classname JdbcDemo1
 * @Description TODO
 * @Date 2020/9/4/004 17:09
 * @Created by Administrator
 */
public class JdbcPrimary {
    private final static Logger logger = LoggerFactory.getLogger(JdbcPrimary.class);
    public void OperMysql(){
        //1. 导入驱动jar包
        //2.注册驱动
        // Class.forName("com.mysql.jdbc.Driver");
        //3.获取数据库连接对象
//        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3", "root", "root");
        try {
//            Connection conn = DriverManager.getConnection("jdbc:mysql:///db3", "root", "root");
//            Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.2.203:3306/db3", "root", "hb2353");
            Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.1.108:3306/db3", "root", "hb2353");
            //4.定义sql语句
            String sql = "update account set balance = 555555 where id = 1";
//        String sql = "update account set balance = 2000";
            //5.获取执行sql的对象 Statement
            Statement stmt = conn.createStatement();
            //6.执行sql
            int count = stmt.executeUpdate(sql);
            //7.处理结果
            logger.info("count=" + count);
            //8.释放资源
            stmt.close();
            conn.close();
        } catch (SQLException throwables) {
            logger.info("OperMysql,error=",throwables);
            throwables.printStackTrace();
        }
    }
}
